// 检查用户信息脚本
require('dotenv').config({ path: '.env.local' });
const mysql = require('mysql2/promise');

async function checkUserInfo() {
  let connection;
  
  try {
    console.log('🔍 开始检查用户信息...\n');
    
    // 连接数据库
    connection = await mysql.createConnection({
      host: process.env.DB_HOST || 'localhost',
      port: parseInt(process.env.DB_PORT || '3306'),
      user: process.env.DB_USER || 'root',
      password: process.env.DB_PASSWORD,
      database: process.env.DB_NAME || 'math_academy',
    });
    
    console.log('✅ 数据库连接成功\n');
    
    // 查询所有用户
    const [users] = await connection.execute(`
      SELECT id, username, email, role, display_name, created_at 
      FROM users 
      ORDER BY id
    `);
    
    console.log('📊 所有用户信息：\n');
    console.table(users);
    
    // 特别检查taotao用户
    const [taotaoUser] = await connection.execute(
      'SELECT * FROM users WHERE username = ?',
      ['taotao']
    );
    
    if (taotaoUser.length > 0) {
      console.log('\n👤 taotao用户详细信息：');
      console.log(JSON.stringify(taotaoUser[0], null, 2));
    } else {
      console.log('\n⚠️  未找到taotao用户');
    }
    
    // 检查admin用户
    const [adminUser] = await connection.execute(
      'SELECT * FROM users WHERE username = ?',
      ['admin']
    );
    
    if (adminUser.length > 0) {
      console.log('\n👤 admin用户详细信息：');
      console.log(JSON.stringify(adminUser[0], null, 2));
    }
    
  } catch (error) {
    console.error('❌ 错误:', error.message);
  } finally {
    if (connection) {
      await connection.end();
    }
  }
}

checkUserInfo();

